package com.blog.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.blog.po.User;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

	public void add(User user) {
		getHibernateTemplate().save(user);
	}

	public void delete(User user) {
		getHibernateTemplate().delete(user);
	}

	public void update(User user) {
		getHibernateTemplate().update(user);
	}

	public List<User> findAll() {
		List list=getHibernateTemplate().find("from User");
		return list;
	}

	public User findByName(String username) {
		List list=getHibernateTemplate().find("select user from User user where user.username='"+username+"'");
		if(list.size()==0){
			return null;
		}else{
			return (User)list.get(0);
		}
	}

}
